package handlers;

import java.util.Random;

import main.MainMap;
import main.MainMenu;
import people.Character;
import people.Enemy;
import constants.Colors;

public class EnemySpawnHandler extends Colors {

	public static void handle() {
		
		Character c = Character.c;
		String type = "";
		MainMap.mainMap.map[c.x][c.y].setBackground(MOB_AND_PLAYER_ON_SAME_SPOT);
		Random rand = new Random();
		Enemy mob = new Enemy(rand.nextInt(c.level + 1), (short) rand.nextInt(4), "Enemy", c.x, c.y);
		if (storage.EnemyStorage.storage[9] != null) {
			mob = null;
			System.gc();
			return;
		}
		storage.EnemyStorage.storeEnemy(mob);
		if (mob.stats[3] > c.stats[3]) {
			int mob_attackType;
			if (mob.job == 1) {
				mob_attackType = 3;
			}
			if (mob.job == 4) {
				mob_attackType = 2;
			}
			else {
				mob_attackType = 1;
			}
			EnemyAttackHandler.handle(c, mob_attackType, mob);
			type += ("You have been ambushed by a Square of Doom");
		}
		else {
		type += ("You have encountered a Square of Doom");
		}
		MainMenu.printInfo(type);
	}
}
